//
//  CNLoginMessageTool.m
//  CsdnPlus
//
//  Created by 邓建东 on 2020/5/22.
//  Copyright © 2020 CSDN. All rights reserved.
//

#import "CNAccountInfoTool.h"
#include <CNBaseTool/CNCategoryHeader.h>
#include <CNBaseTool/UUIDTool.h>

@implementation CNAccountInfoTool

+ (NSString *)appVersion{
    return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
}

+ (NSString *)uuidString{
    return [UUIDTool getUUID] != nil ? [UUIDTool getUUID] : @"";
}

+ (NSString *)getCSDNAccessToken
{
    NSString *accessToken = [NSString stringWithFormat:@"%@%@%@%@",CN_UUID,@"iOS",@"CSDN-APP",@"b85fF96d-7Aa4-4Ec1-bf1D-2133c1A45656"];
    accessToken = [self stringFromMD5WithString:accessToken];
    return accessToken;
}

+ (NSString *)stringFromMD5WithString:(NSString *)string {
    
    if(string == nil || [string length] == 0)
        return nil;
    
    const char *value = [string UTF8String];
    
    unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH];
    CC_MD5(value, strlen(value), outputBuffer);
    
    NSMutableString *outputString = [[NSMutableString alloc] initWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(NSInteger count = 0; count < CC_MD5_DIGEST_LENGTH; count++){
        [outputString appendFormat:@"%02x",outputBuffer[count]];
    }
    return outputString;
}


+ (BOOL)csdnIsAudit
{
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"csdnIsAudit"];
}

+ (BOOL)isLogin
{
    return [self loginStatus];
}

+ (BOOL)loginStatus
{
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    return [[userdefault objectForKey:KLoginStatus] boolValue];
}

+ (void)saveLoginStatus:(BOOL)loginStatus
{
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    [userdefault setObject:@(loginStatus) forKey:KLoginStatus];
    [userdefault synchronize];
}


+ (void)saveAuditToken:(NSString *)auditToken
{
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    [userdefault setObject:auditToken forKey:@"auditToken"];
    [userdefault synchronize];
}

+ (NSString *)auditToken
{
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    return [userdefault objectForKey:@"auditToken"];
}

+ (void)saveAuditUserToken:(NSString *)auditUserToken
{
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    [userdefault setObject:auditUserToken forKey:@"auditUserToken"];
    [userdefault synchronize];
}

+ (NSString *)auditUserToken
{
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    return [userdefault objectForKey:@"auditUserToken"];
}

+(NSString *)userToken
{
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    return [userdefault objectForKey:kUserToken];
}
@end
